/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hitechbangla.fctu.base.radar;

import com.hitechbangla.fctu.utility.GeneralUtil;
import fctu.simulator.HTB_MAIN;
import java.awt.Color;
import java.awt.Graphics;
import java.io.Serializable;

/**
 *
 * @author Asus
 */
public class DeceptionEcm implements EcmDrawable, Serializable {

    private int radarPositionX;
    private int radarPositionY;
    private int aircraftPositionX;
    private int aircraftPositionY;
    private int radarRange;
    DeceptionEcm(int i, int i0, int x, int y, int  radarRange) {
	radarPositionX = i;
	radarPositionY = i0;
	aircraftPositionX = x;
	aircraftPositionY = y;
	this.radarRange = radarRange;
    }

    @Override
    public void draw(Graphics g, EpmType epmType) {
	//throw new UnsupportedOperationException("Not supported yet.");
	//System.out.println("Inside deception ecm "+"X :"+(aircraftPositionX - radarPositionX)+" rad: "+radarRange);
	//System.out.println("extre: "+(aircraftPositionX - radarPositionX + 5* (int)HTB_MAIN.one_px_equivalent_naut)  );
	Color c = g.getColor();
	//g.setColor(Color.black);
	g.setColor(Color.ORANGE);
	int d1 = 0;
	int d2 = 0;
	if (epmType == EpmType.PLD || epmType == EpmType.PRFD) {
//	    d1 = 5 * (int) HTB_MAIN.one_px_equivalent_naut;
//	    d2 = 10 * (int) HTB_MAIN.one_px_equivalent_naut;
	    d1 = 0;
	    d2 = 0;
	}else {
	    d1 = 5 * (int) HTB_MAIN.one_px_equivalent_naut;
	    d2 = 10 * (int) HTB_MAIN.one_px_equivalent_naut;
	}
	double distanceBetweenRadAndArcft = GeneralUtil.distance2D(aircraftPositionX, aircraftPositionY
					    , radarPositionX, radarPositionY);
	int distance = (int) distanceBetweenRadAndArcft;
	if(distance>= radarRange)
	{
	    GeneralUtil.log("Aircraft Out Of range!!");
	}else{
	    if( (int)GeneralUtil.distance2D(aircraftPositionX + d1 ,aircraftPositionY + d1,
		    radarPositionX, radarPositionY) < radarRange )
	    {
		g.fillRect(aircraftPositionX+d1, aircraftPositionY+d1, 6, 6);
	    }
	    if( (int)GeneralUtil.distance2D(aircraftPositionX + d2 ,aircraftPositionY + d2,
		    radarPositionX, radarPositionY) < radarRange )
	    {
		g.fillRect(aircraftPositionX+d2, aircraftPositionY+d2, 6, 6);
	    }
	    if( (int)GeneralUtil.distance2D(aircraftPositionX - d2 ,aircraftPositionY - d2,
		    radarPositionX, radarPositionY) < radarRange )
	    {
		g.fillRect(aircraftPositionX-d2, aircraftPositionY-d2, 6, 6);
	    }
	    if( (int)GeneralUtil.distance2D(aircraftPositionX - d1 ,aircraftPositionY - d1,
		    radarPositionX, radarPositionY) < radarRange )
	    {
		g.fillRect(aircraftPositionX-d1, aircraftPositionY-d1, 6, 6);
	    }
	}
//	if( ((aircraftPositionX + 5* (int)HTB_MAIN.one_px_equivalent_naut) < radarRange) && ((aircraftPositionY + 5* (int)HTB_MAIN.one_px_equivalent_naut) < radarRange ) ) {
//	    //System.out.println("debugging for deception ecm");
//	    g.fillRect( (int) (aircraftPositionX + 5*(int)HTB_MAIN.one_px_equivalent_naut ), (int) (aircraftPositionY + (int)(5* HTB_MAIN.one_px_equivalent_naut)), 6, 6);
//	}
//	
//	if( ((aircraftPositionX + 10* (int)HTB_MAIN.one_px_equivalent_naut) < radarRange )&& ((aircraftPositionY + 10* (int)HTB_MAIN.one_px_equivalent_naut) < radarRange) ) {
//	    g.fillRect((int) (aircraftPositionX + 10* (int)HTB_MAIN.one_px_equivalent_naut), (int) (aircraftPositionY + 10* (int)HTB_MAIN.one_px_equivalent_naut), 6, 6);
//	}
//	
//	if( ( (aircraftPositionX - 5* (int)HTB_MAIN.one_px_equivalent_naut) < radarRange ) && ((aircraftPositionY - 5* (int)HTB_MAIN.one_px_equivalent_naut) < radarRange) ) {
//	    g.fillRect((int) (aircraftPositionX - 5*(int) HTB_MAIN.one_px_equivalent_naut) , (int) (aircraftPositionY - 5*(int) HTB_MAIN.one_px_equivalent_naut), 6, 6);
//	}
//	
//	if( ((aircraftPositionX - 10*(int) HTB_MAIN.one_px_equivalent_naut) < radarRange) && ((aircraftPositionY  - 10* (int)HTB_MAIN.one_px_equivalent_naut) < radarRange) ) {
//	    g.fillRect((int) (aircraftPositionX - 10* (int)HTB_MAIN.one_px_equivalent_naut) , (int) (aircraftPositionY - 10* (int)HTB_MAIN.one_px_equivalent_naut) , 6, 6);
//	}
//	//System.out.println("X : "+(aircraftPositionX + 5* HTB_MAIN.one_px_equivalent_naut) + "  rad: "+radarRange* HTB_MAIN.one_px_equivalent_naut);
//	g.fillRect( (int) (aircraftPositionX + 5* HTB_MAIN.one_px_equivalent_naut), (int) (aircraftPositionY + 5* HTB_MAIN.one_px_equivalent_naut), 6, 6);
//	 g.fillRect((int) (aircraftPositionX + 10* HTB_MAIN.one_px_equivalent_naut), (int) (aircraftPositionY + 10* HTB_MAIN.one_px_equivalent_naut), 6, 6);
//	g.fillRect((int) (aircraftPositionX - 5* HTB_MAIN.one_px_equivalent_naut) , (int) (aircraftPositionY - 5* HTB_MAIN.one_px_equivalent_naut), 6, 6);
//	 g.fillRect((int) (aircraftPositionX - 10* HTB_MAIN.one_px_equivalent_naut) , (int) (aircraftPositionY - 10* HTB_MAIN.one_px_equivalent_naut) , 6, 6);
	//g.fillRect(aircraftPositionX-20, aircraftPositionY-20, 2, 2);
	//g.fillRect(radarPositionX-aircraftPositionX-40, radarPositionY-aircraftPositionY-40, 2, 2);
	//g.fillRect(radarPositionX-aircraftPositionX+20, radarPositionY-aircraftPositionY+20, 2, 2);
	//g.fillRect(radarPositionX-aircraftPositionX+40, radarPositionY-aircraftPositionY+40, 2, 2);
	g.setColor(c);
    } // end of draw
   
}
